//
//  HJCustomSelectContentView.m
//  HondaPro_2
//
//  Created by 贺佳 on 2018/6/14.
//  Copyright © 2018年 glendale. All rights reserved.
//

#import "HJCustomSelectContentView.h"


#import <Masonry/Masonry.h>

@interface HJCustomSelectContentView()

@end
@implementation HJCustomSelectContentView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        //设置标题
        WEAKSELF;
        UILabel*leftView=[[UILabel alloc]init];
        leftView.backgroundColor = [UIColor clearColor];
        leftView.textColor = [UIColor grayColor];
        leftView.font = [UIFont fontWithName:@"ArialMT" size:16];
        leftView.textAlignment=NSTextAlignmentCenter;
        self.titleLabel=leftView;
        [self addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.mas_equalTo(weakSelf);
            make.width.mas_equalTo(120);
        }];
        //按钮
        HJCustomSelectBtn*firstBtn=[[HJCustomSelectBtn alloc]init];
        [self addSubview:firstBtn];
        [firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.bottom.mas_equalTo(weakSelf);
            make.left.mas_equalTo(leftView.mas_right);
        }];
        self.selectBtn=firstBtn;
    }
    return self;
}
-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents{
    [self.selectBtn addTarget:target action:action forControlEvents:controlEvents];
}
-(void)setTitleContent:(NSString *)titleContent
{
    _titleContent=titleContent;
    if ([titleContent containsString:@"*"]) {
        NSMutableAttributedString*att=[[NSMutableAttributedString alloc]initWithString:titleContent];
        [att addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[titleContent rangeOfString:@"*"]];
        self.titleLabel.attributedText=att;
    }else{
        self.titleLabel.text=titleContent;
    }
}
-(void)setTitleWidth:(CGFloat)titleWidth
{
    _titleWidth=titleWidth;
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(titleWidth);
    }];
}
@end
